package com.bootcamp.javase.compare;

import java.util.Arrays;

/**
 * @program: CompareCode
 * @description:
 * @author: Keyu Li
 * @create: 2021-09-07 21:34
 **/

public class TestCat {
    public static void main(String[] args) {
        Cat1[] catSort1 = {new Cat1(3,"aa",2.2),
                new Cat1(1,"bbb", 5.6),
                new Cat1(2,"cccc", 4.0),
                new Cat1(9,"d", 9.9),
                new Cat1(5,"abcde", 0)};
        Arrays.sort(catSort1);
        for (Cat1 cat : catSort1) {
            System.out.println(cat);
        }
    }
}

class Cat1 implements Comparable<Cat1> {
    int age;
    String name;
    double price;

    public Cat1(int age, String name, double price) {
        this.age = age;
        this.name = name;
        this.price = price;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("Cat1{");
        sb.append("age=").append(age);
        sb.append(", name='").append(name).append('\'');
        sb.append(", price=").append(price);
        sb.append('}');
        return sb.toString();
    }

    @Override
    public int compareTo(Cat1 o) {
        return this.age-o.age;
    }
}
